package com.yiren.dbaa.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiren.backstage.currency.enums.CarSignalEnum;
import com.yiren.dbaa.R;

import java.util.List;

/**
 * Describe  、接线配置信号选择适配器
 */
public class WiringSignalAdapter extends BaseAdapter {

    private Context context;
    private List<CarSignalEnum> signalLists;

    public WiringSignalAdapter(Context context, List<CarSignalEnum> signalLists) {
        this.context = context;
        this.signalLists = signalLists;
    }

    @Override
    public int getCount() {
        return signalLists.size();
    }

    @Override
    public Object getItem(int position) {
        return signalLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_wiring_signal, parent, false);
            mHolder = new ViewHolder(convertView);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }
        mHolder.tvSignalName.setText(signalLists.get(position).getDescription());
        mHolder.ivSignalSelect.setImageResource(R.mipmap.dbaf_start_light_off);
        return convertView;
    }

    class ViewHolder {
        TextView tvSignalName;
        ImageView ivSignalSelect;

        public ViewHolder(View itemView) {
            tvSignalName = (TextView) itemView.findViewById((R.id.tv_title));
            ivSignalSelect = (ImageView) itemView.findViewById((R.id.iv_select));
        }
    }
}
